package com.demo.juc.ticket;

/**
 * @Author: shubin_yao
 * @Date: 2022/04/30/10:24
 * @Description: Lamda 改写小程序
 *
 * 接口中有且只有一个接口，成为函数式接口 @FunctionalInterface
 * Lamda 小口诀：拷贝(),写死右箭头，落地大括号
 *
 */

class TicketL {
    private int num = 30;

    public synchronized void saleTicket() {
        if (num > 0) {
            System.out.println("卖出第：" + (num--) + "张票，还剩：" + num + "张票！");
        }
    }

}


public class SaleTicketLamda {

    public static void main(String[] args) {
        TicketL ticket = new TicketL();
        new Thread(() -> {
            for (int i = 0; i < 40; i++) {
                ticket.saleTicket();
            }
        },"A").start();
        new Thread(() -> {
            for (int i = 0; i < 40; i++) {
                ticket.saleTicket();
            }
        },"B").start();

        new Thread(() -> {
            for (int i = 0; i < 40; i++) {
                ticket.saleTicket();
            }
        },"C").start();

    }
}
